package cn.itcast.aop;

import lombok.extern.log4j.Log4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Log4j
public class RunTimeAspect {

    @Around("execution(* cn.itcast.service..*.*(..))")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        long start = System.currentTimeMillis();

        Object result = pjp.proceed(pjp.getArgs());

        long end = System.currentTimeMillis();

        String className = pjp.getSignature().getDeclaringTypeName();
        String methodName = pjp.getSignature().getName();

        log.info(className+"中的"+methodName+"方法,执行花费了"+(end-start)+"毫秒");
        return result;
    }
}
